package com.hudongwx.yuan_sdjj.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.hudongwx.yuan_sdjj.R;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

@ContentView(R.layout.activity_home_dialog)
public class HomeDialogActivity extends AppCompatActivity {
    @ViewInject(R.id.home_dialog_ll)
    private LinearLayout linearLayout;
    private int sex=0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
    }
    @Event(R.id.home_dialog_btn)
    private void submit(View v){
        Intent intent = new Intent();
        intent.putExtra("sex",sex);
        setResult(2,intent);
        finish();
    }
    @Event(value = {R.id.home_dialog_iv_1,
            R.id.home_dialog_iv_2,
            R.id.home_dialog_iv_3})
    private void click(View view){
        if(!view.isSelected()){
            //找到布局控件下有几个控件
            int childCount = linearLayout.getChildCount();
            //设置成默认状态
            for (int i = 0; i < childCount ; i++) {
                linearLayout.getChildAt(i).setSelected(false);
            }
            view.setSelected(true);
            //返回选中的
            for (int i = 0; i < childCount; i++) {
                if(linearLayout.getChildAt(i).isSelected()){
                    sex=i;
                    break;
                }
            }
        }
    }
    @Event(value = {R.id.home_dialog_iv_4,
            R.id.home_dialog_iv_5,
            R.id.home_dialog_iv_6,
            R.id.home_dialog_iv_7,
            R.id.home_dialog_iv_8})
    private void click2(View view){
        view.setSelected(!view.isSelected());
    }

}
